<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
                    xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters;assembly=MaterialDesignThemes.Wpf"
                    xmlns:guiHelper="clr-namespace:DentalGUIHelper;assembly=DentalConfig">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="MaterialDesignTheme.ValidationErrorTemplate.xaml" />
    </ResourceDictionary.MergedDictionaries>
    <converters:TextFieldHintVisibilityConverter x:Key="TextFieldHintVisibilityConverter" />
    <converters:MathConverter Operation="Divide" x:Key="DivisionMathConverter" />

    <Style x:Key="MaterialDesignTimePicker" TargetType="{x:Type wpf:TimePicker}">
		<Setter Property="VerticalAlignment" Value="Center"/>
		<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}"/>
		<Setter Property="BorderBrush" Value="{DynamicResource MaterialDesignTextBoxBorder}" />
		<Setter Property="Background" Value="Transparent"/>
		<Setter Property="BorderThickness" Value="0 0 0 1"/>
		<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="IsTabStop" Value="False"/>
        <Setter Property="wpf:HintAssist.Hint" Value="Select time" />
        <Setter Property="ClockStyle" Value="{DynamicResource MaterialDesignClock}" />
        <Setter Property="Validation.ErrorTemplate" Value="{StaticResource MaterialDesignValidationErrorTemplate}"/>
        <Setter Property="ClockHostContentControlStyle">
            <Setter.Value>
                <Style TargetType="{x:Type ContentControl}">
                    <Style.Setters>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type ContentControl}">
                                    <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
                                        <Border Effect="{DynamicResource MaterialDesignShadowDepth4}" Padding="16 8 16 24">
                                            <ContentPresenter Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" />
                                        </Border>
                                    </AdornerDecorator>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style.Setters>
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type wpf:TimePicker}">
                    <ControlTemplate.Resources>
                        <ControlTemplate x:Key="TextBoxTemplate" TargetType="{x:Type TextBox}">
                            <Grid>
                                <ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" />
                                <wpf:SmartHint x:Name="Hint"
                                               FontSize="{TemplateBinding FontSize}"
                                               UseFloating="{Binding Path=(wpf:HintAssist.IsFloating), RelativeSource={RelativeSource TemplatedParent}}"
                                               FloatingScale="{Binding Path=(wpf:HintAssist.FloatingScale), RelativeSource={RelativeSource TemplatedParent}}"
                                               FloatingOffset="{Binding Path=(wpf:HintAssist.FloatingOffset), RelativeSource={RelativeSource TemplatedParent}}"
                                               Hint="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource TemplatedParent}}"
                                               HintProxy="{Binding RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static converters:HintProxyFabricConverter.Instance}}"
                                               HintOpacity="{Binding Path=(wpf:HintAssist.HintOpacity), RelativeSource={RelativeSource TemplatedParent}}"/>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <MultiTrigger>
                                    <MultiTrigger.Conditions>
                                        <Condition SourceName="Hint" Property="IsContentNullOrEmpty" Value="False" />
                                        <Condition Property="IsKeyboardFocused" Value="True" />
                                    </MultiTrigger.Conditions>
                                    <Setter TargetName="Hint" Property="Foreground" Value="{DynamicResource MidContrastPrimaryBrush}" />
                                    <Setter TargetName="Hint" Property="HintOpacity" Value="1" />
                                </MultiTrigger>
                                <MultiDataTrigger>
                                  <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding Path=(wpf:HintAssist.IsFloating), RelativeSource={RelativeSource Self}}" Value="False" />
                                    <Condition Binding="{Binding Path=(guiHelper:TextboxHelper.HintIsVisible), RelativeSource={RelativeSource Self}}" Value="False"/>
                                  </MultiDataTrigger.Conditions>
                                  <Setter TargetName="Hint" Property="Visibility" Value="Collapsed" />
                                </MultiDataTrigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                        <ControlTemplate x:Key="DropDownButtonTemplate" TargetType="{x:Type Button}">
                            <Grid Background="Transparent">
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualStateGroup.Transitions>
                                            <VisualTransition GeneratedDuration="0"/>
                                            <VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver"/>
                                            <VisualTransition GeneratedDuration="0:0:0.1" To="Pressed"/>
                                        </VisualStateGroup.Transitions>
                                        <VisualState x:Name="Normal"/>
                                        <VisualState x:Name="MouseOver"/>
                                        <VisualState x:Name="Pressed"/>
                                        <VisualState x:Name="Disabled"/>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <Viewbox>
                                    <Canvas Width="24" Height="24">
                                        <Path Data="M12,20A8,8 0 0,0 20,12A8,8 0 0,0 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22C6.47,22 2,17.5 2,12A10,10 0 0,1 12,2M12.5,7V12.25L17,14.92L16.25,16.15L11,13V7H12.5Z" Fill="{TemplateBinding Foreground}" />
                                    </Canvas>
                                </Viewbox>
                            </Grid>
                        </ControlTemplate>
                    </ControlTemplate.Resources>
                    <Grid x:Name="TemplateRoot">
                        <Border BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Background="{TemplateBinding Background}"
                                x:Name="border"
                                Padding="0 4 0 4"
                                SnapsToDevicePixels="True">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <TextBox BorderThickness="0" x:Name="PART_TextBox"
                                         wpf:TextFieldAssist.TextBoxViewMargin=".5 0 0 0"
                                         Margin="0"
                                         Template="{StaticResource TextBoxTemplate}"
                                         />
                                <Button x:Name="PART_Button"
                                        Grid.Column="1"
                                        Foreground="{TemplateBinding BorderBrush}"
                                        Focusable="False"
                                        HorizontalAlignment="Right"
                                        Margin="4 0 0 -3"
                                        Template="{StaticResource DropDownButtonTemplate}"
                                        Padding="0"
                                        Height="17" />
                                <Popup x:Name="PART_Popup" AllowsTransparency="True"
                                       Placement="Custom"
                                       CustomPopupPlacementCallback="{x:Static wpf:CustomPopupPlacementCallbackHelper.LargePopupCallback}"
                                       PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"
                                       PopupAnimation="Fade"/>
                            </Grid>
                        </Border>
                        <Line x:Name="DashedLine" VerticalAlignment="Bottom" Visibility="Hidden"
                              StrokeThickness="{Binding BorderThickness.Bottom, ElementName=border, Converter={StaticResource DivisionMathConverter}, ConverterParameter=0.75}" StrokeDashArray="1,2.5" StrokeDashCap="Round"
                              X1="0" X2="{Binding ActualWidth, ElementName=border}" Y1="0" Y2="0"
                              Stroke="{TemplateBinding BorderBrush}" Opacity="0.56" />
                        <wpf:Underline x:Name="Underline" Visibility="{Binding Path=(wpf:TextFieldAssist.DecorationVisibility), RelativeSource={RelativeSource TemplatedParent}}"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Opacity" TargetName="TemplateRoot" Value="0.56"/>
                            <Setter Property="Visibility" TargetName="DashedLine"  Value="Visible" />
                            <Setter Property="BorderBrush" TargetName="border" Value="Transparent"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="BorderBrush" Value="{DynamicResource MidContrastPrimaryBrush}"/>
                        </Trigger>
                        <Trigger Property="IsKeyboardFocusWithin" Value="true">
                            <Setter Property="IsActive" TargetName="Underline" Value="True"/>
                            <Setter Property="BorderBrush"  Value="{DynamicResource MidContrastPrimaryBrush}"/>
                        </Trigger>
                        <Trigger Property="Validation.HasError" Value="true">
                            <Setter Property="BorderBrush" Value="{DynamicResource ValidationErrorBrush}"/>
                            <Setter TargetName="Underline" Property="Background" Value="{DynamicResource ValidationErrorBrush}"/>
                        </Trigger>
                        <Trigger Property="wpf:HintAssist.IsFloating" Value="True">
                            <Setter TargetName="border" Property="Margin" Value="0 12 0 0" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="MaterialDesignFloatingHintTimePicker" TargetType="{x:Type wpf:TimePicker}" BasedOn="{StaticResource MaterialDesignTimePicker}">
        <Setter Property="wpf:HintAssist.IsFloating" Value="True"/>
    </Style>

    <Style x:Key="{x:Type wpf:TimePicker}" TargetType="{x:Type wpf:TimePicker}" BasedOn="{StaticResource MaterialDesignTimePicker}"/>
</ResourceDictionary>
